module ADC128S102_Driver_top(
	clk,
	rst_n,
	key,
	led,
	addr,
	ADC_SCLK,
	ADC_CS_N,
	ADC_DIN,
	ADC_DOUT,
	DIO,
	SRCLK,
	RCLK
);

	input clk;
	input rst_n;
	input key;
	output reg led;
	input [2:0] addr;
	output ADC_SCLK;
	output ADC_CS_N;
	output ADC_DIN;
	input ADC_DOUT;
	output DIO;
	output SRCLK;
	output RCLK;
	
	wire [11:0] data;
	wire conv_done;
	wire conv_go;
	wire Key_P_Flag;
	wire [31:0] disp_data;
	
	assign disp_data = {20'd0,data};
	
	assign conv_go = Key_P_Flag;
	
key_filter key_filter_inst(
	.clk(clk),
	.rst_n(rst_n),
	.key(key),
	.key_p_flag(Key_P_Flag),
	.key_r_flag(),
	.key_state()
);

ADC128S102_Driver ADC128S102_Driver_inst(
	.clk(clk),
	.rst_n(rst_n),
	.conv_go(conv_go),
	.addr(addr),
	.conv_done(conv_done),
	.data(data),
	.ADC_SCLK(ADC_SCLK),
	.ADC_CS_N(ADC_CS_N),
	.ADC_DIN(ADC_DIN),
	.ADC_DOUT(ADC_DOUT)
);
	
hex8_HC595_top hex8_HC595_top(
	.clk(clk),
	.rst_n(rst_n),
	.DIO(DIO),
	.data(disp_data),
	.SRCLK(SRCLK),
	.RCLK(RCLK)
);

	always@(posedge clk or negedge rst_n)
		if(!rst_n)
			led <= 0;
		else if(conv_done)
			led <= ~led;

endmodule
